package com.groupnections.client.Entities;

import java.util.List;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.googlecode.objectify.Key;
import com.groupnections.client.GlobalVariables;
import com.groupnections.shared.Entity;

/**
 * 
 * @UserManual
 */
public class EntitiesList extends VerticalPanel {

	public EntitiesList(List<Key<Entity>> entities) {

		if (entities != null) {

			for (Key<Entity> entityKey : entities) {

				Entity entity = GlobalVariables.entitiesMap.get(entityKey
						.getName());

				if (entity != null
						&& Entity.PROJECT_TYPE.equals(entity.getEntityType())) {

					this.add(entityLink(entity));
				}
			}
		}
	}

	private Anchor entityLink(final Entity entity) {

		Anchor entityAnchor = new Anchor(entity.getEntityName());
		entityAnchor.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				new InitializeEntity(entity);
			}
		});

		return entityAnchor;
	}

}
